<template>
  <swiper id="swiper" ref="mySwiper" :options="swiperOption">
    <!-- slides -->
    <swiper-slide v-for="sowing in sowingList" :key="sowing.public_id">
      <img :src="sowing.icon_url" :alt="sowing.public_name">
    </swiper-slide>
    <!-- Optional controls -->
    <div slot="pagination" class="swiper-pagination" />
  </swiper>
</template>

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

export default {
  name: 'Sowing',
  components: {
    swiper,
    swiperSlide
  },
  props: {
    sowingList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      swiperOption: {
        notNextTick: true,
        // 分页
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        // 循环
        loop: true,
        // 切换时长
        autoplay: {
          delay: 1000
        },
        // 速度
        speed: 600,
        // 滑动后回调函数
        on: {
          slideChangeTransitionEnd() {
            // console.log(this.activeIndex);
          }
        }
      }
    }
  },
  computed: {
    swiper() {
      console.log('mySwiper: ', this.$refs.mySwiper.swiper)
      return this.$refs.mySwiper.swiper
    }
  },
  mounted() {
    // this.swiper.slideTo(5, 1000, false);
    console.log('this.swiper', this.swiper)
    this.swiper.slideTo(5, 1000, false)
  }
}
</script>

<style lang="scss" scoped>
    #swiper {
        width: 100%;
        background-color: transparent;
        margin-top: 50px;
    }

    #swiper img{
        width: 100%;
        height: 100%;
    }

    /*
      穿透修改样式
   */
    #swiper ::v-deep .swiper-pagination-bullet-active{
        background-color: #75a342 ;
    }
</style>
